package com.botao.tip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.botao.tip.dao.FinanceMapper;
import com.botao.tip.dao.FinanceTotalMapper;
import com.botao.tip.dao.ProductMapper;
import com.botao.tip.entity.Finance;
import com.botao.tip.entity.FinanceTotal;
import com.botao.tip.entity.Product;
import com.botao.tip.service.FinanceService;
import com.botao.tip.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : vip865047755@126.com
 * @version :JDK1.8
 * @date : 2020-12-04 20:00
 * @File : FinanceServiceImpl.java
 * @software: IntelliJ IDEA
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FinanceServiceImpl extends ServiceImpl<FinanceMapper, Finance> implements FinanceService {
    @Autowired
    private FinanceMapper financeMapper;

    @Autowired
    private FinanceTotalMapper financeTotalMapper;

    @Override
    public boolean insert(Finance finance) {
        int f_in = finance.getfIn();
        int f_out = finance.getfOut();
        int total = f_in - f_out;
        FinanceTotal financeTotal = new FinanceTotal();
        financeTotal.setTotal(total);
        financeTotalMapper.insert(financeTotal);
        int insert = financeMapper.insert(finance);
        return insert != 0;
    }

    @Override
    public Map<String, Integer> inOuts() {
        HashMap<String, Integer> map = new HashMap<>();
        int i = financeMapper.inCome();
        int out = financeMapper.out();
        map.put("in", i);
        map.put("out", out);
        return map;
    }


}
